//
//  Buy1DropCategrayView.swift
//  jiaoyi
//
//  Created by 易万军 on 2018/11/8.
//  Copyright © 2018 wjk. All rights reserved.
//

import UIKit

class Buy1DropCategrayView: YNDropDownView {
    
    @IBOutlet weak var tableView: UITableView!
    
    var selectItemBlock: ((AutionCategory) -> ())?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = UIColor.clear
        backgroundColor = UIColor.clear
//        tableView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(self.openMessage(_:))))
    }
    
    @objc func openMessage(_ bar : UIBarButtonItem) {
        self.hideMenu()
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.hideMenu()
//        self.isHidden = true
    }
    
    var categories: [AutionCategory]!{
        didSet{
            tableView.reloadData()
        }
    }
}
extension Buy1DropCategrayView: UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return categories.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil{
            cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
            cell?.backgroundColor = UIColor.white
        }
        cell?.textLabel?.text = categories[indexPath.row].name
        cell?.textLabel?.font = UIFont.systemFont(ofSize: 14)
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectItemBlock?(categories[indexPath.row])
        self.hideMenu()
        
    }
}
